package com.qianfeng.zhangwei.xutils.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.qianfeng.zhangwei.xutils.R;

import java.util.List;

/**
 * @说 明：
 * @项目名称：Sz1504Adv
 * @包 名： com.qianfeng.zhangwei.xutils.adapter
 * @类 名： RecyclerBaseAdapter
 * @创 建人： zhangwei
 * @创建时间：2015-08-05 14:36
 * @版 本：v1.0
 * @修 改人：
 * @修改时间：
 * @修改备注：
 */
public class RecyclerBaseAdapter extends RecyclerView.Adapter<RecyclerBaseAdapter.RcViewHolder> {
    private List<String> list;
    private OnItemClickLinstener onItemClickLinstener;


    public RecyclerBaseAdapter(List<String> list) {
        this.list = list;
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    @Override
    public RcViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.widget_item_rc_layout, parent, false);
        RcViewHolder vh = new RcViewHolder(view);
        return vh;
    }

    @Override
    public void onBindViewHolder(RcViewHolder holder, int position) {
        holder.text.setText(list.get(position));
    }


    public class RcViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
        private TextView text;

        public RcViewHolder(View itemView) {
            super(itemView);
            itemView.setOnClickListener(this);
            this.text = (TextView) itemView.findViewById(R.id.item_rc_img);
        }

        @Override
        public void onClick(View v) {
            if (onItemClickLinstener != null) {
                onItemClickLinstener.onItemClickLinstener(list.get(getLayoutPosition()));
            }
        }
    }


    public interface OnItemClickLinstener {

        public void onItemClickLinstener(String str);

    }

    public void setOnItemClickLinstener(OnItemClickLinstener onItemClickLinstener) {
        this.onItemClickLinstener = onItemClickLinstener;
    }
}
